﻿create procedure [File].[WriteAllText] ( @p_Path varchar(255), @p_Text varchar(max) )
as
begin

  set nocount on;

  declare @fileSystemObject int;
  declare @fileStream int;
	declare @StatusCode int;

  execute @StatusCode = sp_OACreate 'Scripting.FileSystemObject' , @fileSystemObject out

  if @StatusCode = 0 execute @StatusCode = sp_OAMethod @fileSystemObject, 'CreateTextFile' , @fileStream out, @p_Path, True
  if @StatusCode = 0 execute @StatusCode = sp_OAMethod @fileStream, 'Write', Null, @p_Text
  if @StatusCode = 0 execute @StatusCode = sp_OAMethod @fileStream, 'Close'

  execute sp_OADestroy @fileStream
  execute sp_OADestroy @fileSystemObject

end